package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbPermission;
import com.oig.sys.auth.vo.PermissionVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ITbPermissionDao extends JpaRepository<TbPermission, Integer> {


    TbPermission getTbPermissionById(Integer id);

    TbPermission findByApiUrl(String apiUrl);

    TbPermission findByApiUrlAndFlag(String apiUrl, String flag);


    @Query("select new com.oig.sys.auth.vo.PermissionVo(p.id, p.systemId, p.apiUrl,p.apiName,p.apiDesc,p.status,p.createUserName,p.createTime,p.lastUpdateName,p.lastUpdateTime,p.flag)" +
            " from TbPermission p where p.id in(:idList)")
    List<PermissionVo> findByIdList(@Param("idList") List<Integer> idList) ;


    @Query("select new com.oig.sys.auth.vo.PermissionVo(p.id, p.systemId, p.apiUrl,p.apiName,p.apiDesc,p.status,p.createUserName,p.createTime,p.lastUpdateName,p.lastUpdateTime,p.flag)" +
            " from TbPermission p where p.flag='1' and p.status='04'")
    List<PermissionVo> findByNoAuthList() ;
}
